var project_edit = function () {
	var submit_form = function () {
		$('#project_form').ajaxForm({
			dataType    : 'json',
			beforeSubmit: function () {
				if (!$('#teamAccount').val()) {
					cdms.common.show_error('tr_form_msg', language.project.chose_team_account_msg);
					return false;
				}
				$('#btn_submit').attr('disabled', 'disabled');
				cdms.common.show_info('tr_form_msg', language.project.wait_submit_msg);

			},
			success     : function (json) {
				$('#btn_submit').removeAttr('disabled');
				if (json.type) {
					$.alert({
						title  : language.note.alert_title,
						message: json.msg,
						fnOk   : function () {
							window.location.href = "project/list";
						}
					});
				} else {
					cdms.common.show_error('tr_form_msg', json.msg);
				}
			}
		});
		$("#project_form").submit();
	};
	return {
		init: function () {

		},

		more_detail : function() {
			window.location.href = "../moreinfo";
		},
		choose_account : function () {
			var choose_team = $('#team_account_select option:selected');
			var team_accounts = [];
			var team_lables = [];
			$.each(choose_team, function (idx, val) {
				team_accounts.push(val.value);
				team_lables.push(val.text);
			});
			$('#teamAccount').val(team_accounts.join(','));
			$('#team_label').textbox({
				text: team_lables.join(',')
			});
			$('#layer1').layer().close();
		},
		open_team_layer: function () {
			$("#layer1").layer().open();

			$("#team_account_select").pickList({items: teamAccout_json, sourceListLabel: language.project.pklist_msg.all, targetListLabel: language.project.pklist_msg.checked});
		},
		//todo 暂时使用button onclick事件代替,以后加以改善
		form_submit    : function () {
            if (!$.isValid()) {
                return false;
            }
			if (js_param.pid_param == 0) {
				var code = $("#code").attr("value");
                code=code.replace(/&/g,"&amp").replace(/</g,"&lt").replace(/>/g,"&gt");
				cdms.common.confirm(language.project.confirm_msg1 + "'" + code + "'" + language.project.comfirm_msg2, function () {
					submit_form();
				});
			} else {
				submit_form();
			}
		}
	}
}();

$(document).ready(function () {
	project_edit.init();


	$("#layer1").layer({title: language.project.pklist_msg.title, height: 350});
	$('#choose_team_account').click(project_edit.open_team_layer);
	$('#team_label').bind('dblclick', project_edit.open_team_layer);
	//页面加载时，初始化lead的combobox
	$('#lead_text').combobox({
		url      : "all_leaders",
		emptyText: language.project.chose_leader,
		onselect : function () {
			$("#lead").attr("value", $('#lead_text').combobox("value"));
		}
	});
	//页面加载时，初始化lead_dev的combobox
	$('#dev_leader_text').combobox({
		url      : "all_leaders",
		emptyText: language.project.chose_header,
		onselect : function () {
			$("#dev_leader").attr("value", $('#dev_leader_text').combobox("value"));
		}
	});
});
